package game.ubibomb;

import org.apache.cordova.DroidGap;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.webkit.WebView;
import android.widget.Toast;

public class MyClass {
	
	@SuppressWarnings("unused")
	private WebView mAppView;
	private DroidGap mGap;
	  
	String standardVolume = "50",
			standardVibration = "on",
			standardControls = "on",
			standardAvatar = "char02",
			standardName = "HardBernd",
			standardIp = "192.168.2.141:9000";
	
	public MyClass(DroidGap gap, WebView view){
		mAppView = view;
	    mGap = gap;
	}
	
    public void showToast(String msg){
		Toast.makeText(mGap.getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }
    
    public String readSharedPrefs(){
    	SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mGap);
    	String volume = sharedPref.getString("ubibomb_volume", standardVolume),
    			vibration = sharedPref.getString("ubibomb_vibration", standardVibration),
    			controls = sharedPref.getString("ubibomb_controls", standardControls),
    			avatar = sharedPref.getString("ubibomb_avatar", standardAvatar),
    			name = sharedPref.getString("ubibomb_name", standardName),
    			ip = sharedPref.getString("ubibomb_ip", standardIp);
    	
    	return volume+"#"+vibration+"#"+controls+"#"+avatar+"#"+name+"#"+ip;
    }
    
    public void writeSharedPrefs(String s){
    	SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mGap);
    	Editor e = sharedPref.edit();
    	String[] parts = s.split("#");
    	e.putString("ubibomb_volume", parts[0]);
    	e.putString("ubibomb_vibration", parts[1]);
    	e.putString("ubibomb_controls", parts[2]);
    	e.putString("ubibomb_avatar", parts[3]);
    	e.putString("ubibomb_name", parts[4]);
    	e.putString("ubibomb_ip", parts[5]);
    	e.commit();
    }
}
